/*
 *  Fontbis.h
 *  sfml-zevil
 *
 *  Created by Jones on Jul-16.
 *  Copyright 2012 dfsfsd. All rights reserved.
 *
 */

#include "stdafx.h"

 class Fontbis : public Fontbis
 {

	bool loadFromFile(const std::string& filename)
	{
	    // Cleanup the previous resources
	    cleanup();
	    m_refCount = new int(1);

	    // Initialize FreeType
	    // Note: we initialize FreeType for every font instance in order to avoid having a single
	    // global manager that would create a lot of issues regarding creation and destruction order.
	    FT_Library library;
	    if (FT_Init_FreeType(&library) != 0)
	    {
	        err() << "Failed to load font \"" << filename << "\" (failed to initialize FreeType)" << std::endl;
	        return false;
	    }
	    m_library = library;

	    // Load the new font face from the specified file
	    FT_Face face;
	    if (FT_New_Face(static_cast<FT_Library>(m_library), filename.c_str(), 0, &face) != 0)
	    {
	        err() << "Failed to load font \"" << filename << "\" (failed to create the font face)" << std::endl;
	        return false;
	    }

	    // Select the unicode character map
	    if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0)
	    {
	        err() << "Failed to load font \"" << filename << "\" (failed to set the Unicode character set)" << std::endl;
	        return false;
	    }

	    // Store the loaded font in our ugly void* :)
	    m_face = face;

	    return true;
	}
};
